package org.balabala.user.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import org.balabala.user.entity.VideoEntity;
import org.balabala.user.service.VideoService;
import org.balabala.user.utils.PageUtils;
import org.balabala.user.utils.Resp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;





/**
 * 
 *
 * @author hanshanxi
 * @email 3176988793@qq.com
 * @date 2021-09-04 09:31:53
 */
@RestController
@RequestMapping("balabala/video")
public class VideoController {
    @Autowired
    private VideoService videoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public Resp list(@RequestParam Integer page, @RequestParam Integer limit,@RequestParam String key,@RequestParam Integer state){
        HashMap<String,Object> hashMap = new HashMap<>();
        hashMap.put("keyword",key);
        hashMap.put("page",page.toString());
        hashMap.put("limit",limit.toString());
        hashMap.put("state",state);
        PageUtils pageUtils = videoService.listByKey(hashMap);
        return Resp.ok().put("data", pageUtils);
    }

    //进行上架操作
    @RequestMapping("/verify")
    public Resp delete(@RequestBody HashMap<String,Object> hashMap){

        Integer id = (Integer)hashMap.get("id");
        Integer state = (Integer)hashMap.get("state");
        boolean b = videoService.banById(id,state);

        if(b){
            return Resp.ok();
        }else {
            return Resp.error(500,"删除失败");
        }
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{videoId}")

    public Resp info(@PathVariable("videoId") Long videoId){
		VideoEntity video = videoService.getById(videoId);

        return Resp.ok().put("video", video);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public Resp save(@RequestBody VideoEntity video){
		videoService.save(video);

        return Resp.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public Resp update(@RequestBody VideoEntity video){
		videoService.updateById(video);

        return Resp.ok();
    }

    /**
     * 删除
//     */
//    @RequestMapping("/delete")
//
//    public Resp delete(@RequestBody Long[] videoIds){
//		videoService.removeByIds(Arrays.asList(videoIds));
//
//        return Resp.ok();
//    }

}
